<?php
include_once("../includes/config.php");
$retour = mysql_query('SELECT * FROM newsletter_membres') or die(mysql_error());

while ($donnees = mysql_fetch_array($retour)) // On fait une boucle pour lister les news
{
	$pseudo = $donnees['pseudo'];
	$id = $donnees['id'];
	$retour2 = mysql_query('SELECT * FROM newsletter_notes WHERE id = '.$id) or die(mysql_error());
	while ($donnees2 = mysql_fetch_array($retour2)) // On fait une boucle pour lister les news
	{
	@$note = $donnees2['total_value']/$donnees2['total_votes'];
	echo '<p>'.$pseudo.'<br />';
	echo 'Note : '.$note.'<br />';
	mysql_query('UPDATE newsletter_membres SET notes="'.$note.'" WHERE ID='.$id.'');
	}
	// Séparation entre les deux parties
	$pseudo = mysql_real_escape_string($pseudo);
	$retour3 = mysql_query('SELECT count(*) FROM newsletter_abonnes WHERE validation=1 AND newsletter="'.$pseudo.'"') or die(mysql_error());
	$resultat=mysql_fetch_row($retour3); 
	$nb_abonnes = $resultat[0];
	$nb_abonnes = mysql_real_escape_string($nb_abonnes);
	echo 'Nb d\'abonnés : '.$nb_abonnes.'<br />';
	mysql_query('UPDATE newsletter_membres SET abonnes="'.$nb_abonnes.'" WHERE pseudo="'.$pseudo.'"');
	// Séparation
	$retour4 = mysql_query('SELECT count(*) FROM newsletter_newsletters WHERE (statut=1 OR statut=3) AND newsletter="'.$pseudo.'"') or die(mysql_error());
	$resultat=mysql_fetch_row($retour4); 
	$nb_news = $resultat[0];
	$nb_news = mysql_real_escape_string($nb_news);
	echo 'Nb news : '.$nb_news.'</p>';
	mysql_query('UPDATE newsletter_membres SET newsletters="'.$nb_news.'" WHERE pseudo="'.$pseudo.'"');
}

